import 'package:tender_flutter/page/subscription/model/subscription_entity.dart';

subscriptionEntityFromJson(SubscriptionEntity data, Map<String, dynamic> json) {
	if (json['pageNum'] != null) {
		data.pageNum = json['pageNum'] is String
				? int.tryParse(json['pageNum'])
				: json['pageNum'].toInt();
	}
	if (json['pageSize'] != null) {
		data.pageSize = json['pageSize'] is String
				? int.tryParse(json['pageSize'])
				: json['pageSize'].toInt();
	}
	if (json['total'] != null) {
		data.total = json['total'] is String
				? int.tryParse(json['total'])
				: json['total'].toInt();
	}
	if (json['pages'] != null) {
		data.pages = json['pages'] is String
				? int.tryParse(json['pages'])
				: json['pages'].toInt();
	}
	if (json['list'] != null) {
		data.xList = new List<SubscriptionList>();
		(json['list'] as List).forEach((v) {
			data.xList.add(new SubscriptionList().fromJson(v));
		});
	}
	if (json['isFirstPage'] != null) {
		data.isFirstPage = json['isFirstPage'];
	}
	if (json['isLastPage'] != null) {
		data.isLastPage = json['isLastPage'];
	}
	return data;
}

Map<String, dynamic> subscriptionEntityToJson(SubscriptionEntity entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['pageNum'] = entity.pageNum;
	data['pageSize'] = entity.pageSize;
	data['total'] = entity.total;
	data['pages'] = entity.pages;
	if (entity.xList != null) {
		data['list'] =  entity.xList.map((v) => v.toJson()).toList();
	}
	data['isFirstPage'] = entity.isFirstPage;
	data['isLastPage'] = entity.isLastPage;
	return data;
}

subscriptionListFromJson(SubscriptionList data, Map<String, dynamic> json) {
	if (json['areas'] != null) {
		data.areas = json['areas']?.map((v) => v.toString())?.toList()?.cast<String>();
	}
	if (json['keyword'] != null) {
		data.keyword = json['keyword']?.map((v) => v.toString())?.toList()?.cast<String>();
	}
	if (json['lastTitle'] != null) {
		data.lastTitle = json['lastTitle'].toString();
	}
	if (json['isPoint'] != null) {
		data.isPoint = json['isPoint'];
	}
	if (json['num'] != null) {
		data.num = json['num'] is String
				? int.tryParse(json['num'])
				: json['num'].toInt();
	}
	if (json['isPush'] != null) {
		data.isPush = json['isPush'] is String
				? int.tryParse(json['isPush'])
				: json['isPush'].toInt();
	}
	if (json['begin'] != null) {
		data.begin = json['begin'].toString();
	}
	if (json['type'] != null) {
		data.type = json['type'].toString();
	}
	if (json['id'] != null) {
		data.id = json['id'] is String
				? int.tryParse(json['id'])
				: json['id'].toInt();
	}
	if (json['area_ids'] != null) {
		data.areaIds = json['area_ids']?.map((v) => v is String
				? int.tryParse(v)
				: v.toInt())?.toList()?.cast<int>();
	}
	return data;
}

Map<String, dynamic> subscriptionListToJson(SubscriptionList entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['areas'] = entity.areas;
	data['keyword'] = entity.keyword;
	data['lastTitle'] = entity.lastTitle;
	data['isPoint'] = entity.isPoint;
	data['num'] = entity.num;
	data['isPush'] = entity.isPush;
	data['begin'] = entity.begin;
	data['type'] = entity.type;
	data['id'] = entity.id;
	data['area_ids'] = entity.areaIds;
	return data;
}